import '../helper/dioHelper2.dart';

class FileSpace {
  int ID;
  String Guid;
  int TypeId;
  String Category;
  String Name;
  String Description;
  String Field1;
  String Field2;
  String Field3;
  String CreateTM;
  int State;
  String AuthRead;
  String AuthWrite;
  String CreateUser;

  FileSpace(
      this.ID,
      this.Guid,
      this.TypeId,
      this.Category,
      this.Name,
      this.Description,
      this.Field1,
      this.Field2,
      this.Field3,
      this.CreateTM,
      this.State,
      this.AuthRead,
      this.AuthWrite,
      this.CreateUser);
  FileSpace.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        TypeId = json["TypeId"],
        Category = json["Category"],
        Name = json["Name"],
        Description = json["Description"],
        Field1 = json["Field1"],
        Field2 = json["Field2"],
        Field3 = json["Field3"],
        CreateTM = json["CreateTM"],
        State = json["State"],
        AuthRead = json["AuthRead"],
        AuthWrite = json["AuthWrite"],
        CreateUser = json["CreateUser"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'TypeId': TypeId,
        'Category': Category,
        'Name': Name,
        'Description': Description,
        'Field1': Field1,
        'Field2': Field2,
        'Field3': Field3,
        'CreateTM': CreateTM,
        'State': State,
        'AuthRead': AuthRead,
        'AuthWrite': AuthWrite,
        'CreateUser': CreateUser,
      };
  static Future<bool> Add(FileSpace x1) async {
    var response = await DioHelper.Post("/FileSpace/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(FileSpace x1) async {
    var response = await DioHelper.Post("/FileSpace/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(FileSpace x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/FileSpace/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<FileSpace?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/FileSpace/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return new FileSpace.fromJson(response.data);
    return null;
  }

  static Future<List<FileSpace>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/FileSpace/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <FileSpace>[];
    if (response.statusCode == 200) {
     
      for (var x in response.data) {
        list1.add(new FileSpace.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<FileSpace>> GetAllList() async {
    var response = await DioHelper.Get("/FileSpace/GetList", {});
    var list1 = <FileSpace>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new FileSpace.fromJson(x));
      }
    }
    return list1;
  }

    static Future<List<String>> GetTypeList() async {
    var response = await DioHelper.Get("/FileSpace/GetTypeList", {});
    var list1 = <String>[];
    if (response.statusCode == 200) {
       print(response.data);
      list1=List<String>.from( response.data);
    }
    return list1;
  }
}
